<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../js/jquery-1.10.1.min.js"></script>
  <style>
    * {
      padding: 0;
      margin: 0;
    }

    .wrap {
      width: 400px;
      height: 400px;
      background-color: red;
      margin: 100px;
      overflow: hidden;
      /* position:relative; */
    }

    .sub {
      width: 300px;
      height: 300px;
      background-color: orange;
      margin: 50px;
      overflow: hidden;
      position: relative;
    }

    .txt {
      width: 100px;
      height: 100px;
      background-color: #000;
      margin: 100px;
    }

    /* -------------------------------------------------- */
    html {
      height: 10000px;
    }

    .group {
      position: fixed;
      right: 20px;
      bottom: 20px;
    }
  </style>
</head>

<body>
  <!--  <div class="wrap">
    <div class="sub">
      <div class="txt"></div>
    </div>
  </div>
 -->
  <div class="group">
    <button>设置</button>
  </div>
</body>
<script>

  // console.log($(".txt").offsetParent());
  // console.log($(".txt").prop("offsetParent"));
  // console.log($(".txt").prop("offsetLeft"), $(".txt").prop("offsetTop"));

  console.log("-----------------------------------------------------------------------");

  // $(ele).offset()  => 返回匹配的元素相对于 文档左上角的偏移   {left,top}
  // console.log($(".txt").offset()); // =>{top: 250, left: 250}
  // console.log($(".txt").offset().left, $(".txt").offset().top); //=> 250 250

  console.log("-----------------------------------------------------------------------");

  // scrollTop()  获取和设置 滚动条距离文档左边的位置
  window.onscroll = function () {
    var scrollTop = document.documentElement.scrollTop;
    $(document).scrollTop();
    console.log($(document).scrollTop(), scrollTop);
  }

  $("button").eq(0).click(function () {
    //设置
    // document.documentElement.scrollTop = 0

    // window.scrollTo(0, 0)

    // window.scrollTo({
    //   top: 0,
    //   behavior: "smooth", // smooth="光滑的"
    // })


    $(document).scrollTop(0);


  })




</script>

</html>